import React, { useState } from 'react';
// 公共头部
import Header from '../components/Header'
// 广告组件
// 底部copy
import { Row, Col, List, Breadcrumb } from 'antd'

// 主页放轮播图
import Footer from '../components/Foot';
import axios from 'axios'
import servicePath from '../config/apiUrl'
import Link from 'next/link'



const Mylist = (list) => {
    const [mylist, setMylist] = useState(list.data);
    return (
        <div>
            <Header className="header"></Header>

            <Row className="comm-main" type='flex' justify='center'>
                <Col className="comm-left" xs={24} sm={24} md={15} lg={10} xl={13}>
                    <div className="bread-div">
                        <Breadcrumb>
                            <Breadcrumb.Item><a href="/">首页</a></Breadcrumb.Item>
                            <Breadcrumb.Item>文章列表</Breadcrumb.Item>
                        </Breadcrumb>
                    </div>
                    <List
                        size="large"
                        dataSource={mylist}
                        renderItem={item => (
                            <List.Item>
                                <Link href={{ pathname: '/detail', query: { id: item.id } }}>
                                    <a>{item.title}</a>
                                </Link>
                                <div className="list-content">{item.introduce}</div>
                            </List.Item>
                        )}
                    />
                </Col>
                <Col className='comm-right' xs={0} sm={0} md={8} lg={5} xl={4}>
                    {/* 广告组件 */}
                    {/* <Advert></Advert> */}
                </Col>
            </Row>

            <Footer></Footer>
        </div>
    )
}

Mylist.getInitialProps = async () => {
    const promise = new Promise((resolve) => {
        axios(servicePath.getArticleList).then(
            (res) => {
                console.log(res.data)
                resolve(res.data)
            }
        )
    })

    return await promise
}

export default Mylist
